#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include"xh.h"
 struct Sqstack {
	ElementType* arr;
	int capicity;
	int topstack;
};

stack creatSqstack() {
	stack S = (ptrSqstack)malloc(max_size*sizeof(struct Sqstack));
	if (S == NULL) {
		perror("malloc");
		return NULL;
	}
	S->arr = NULL;
	S->capicity = S->topstack = 0;
	return S;
}

void grow(stack S) {
	if (S->capicity == S->topstack) {
		int newcapicity = 2 * S->capicity;
		ElementType* tmp = realloc(S->arr, newcapicity * sizeof(ElementType));
		if (tmp == NULL) {
			perror("realloc");
			return ;
		}
		S->arr = tmp;
		S->capicity = newcapicity;
	}
}

int IsEmpety(stack S) {
	return S->arr == NULL;
}

void push(stack S,ElementType x) {
	grow(S);
	S->arr[S->topstack] = x;
	S->topstack++;
}
ElementType top(stack S) {
	if (!IsEmpety(S)) {
		return S->arr[S->topstack-1];
	}
    printf("Empety stack");
	return 0;
}

void pop(stack S) {
	if (IsEmpety(S)) {
		printf("Empety stack");
	}
	else {
		S->topstack--;
	}
}

void showstack(stack S) {
	int i = 0;
	for (i = 0; i < S->topstack;i++) {
		printf("%d ", S->arr[i]);
	}
	printf("\n");
}